package net.println.kotlin.chapter5.closure

fun makeFun(): () -> Unit {
    var count = 0
    return fun() {
        println(++count)
    }
}

fun fibonacci(): Iterable<Long> {
    var first = 0L
    var second = 1L
    return Iterable {
        object : LongIterator() {
            override fun hasNext(): Boolean {
                return true
            }

            override fun nextLong(): Long {
                val result = second
                second += first
                first = second - first
                return result
            }

        }
    }
}

fun main(args: Array<String>) {
    val add2 = add(5)
    println(add2(2))
}

//fun add(x: Int) = fun(y: Int) = x + y

fun add(x: Int): (Int) -> Int {
    data class Person(val name: String, val age: Int)
    return fun(y: Int): Int {
        return x + y
    }
}